#include "HeartbeatDetectionRequest.h"

HeartbeatDetectionRequest::HeartbeatDetectionRequest() {}

HeartbeatDetectionRequest::HeartbeatDetectionRequest(QString factoryNo, QString transId, QDateTime eventTime, QString eventUser, QString machineNo, QString connectStatus):\
    factoryNo(factoryNo),
    transId(transId),
    eventTime(eventTime),
    eventUser(eventUser),
    machineNo(machineNo),
    connectStatus(connectStatus)
{

}

QByteArray HeartbeatDetectionRequest::toJson() const
{
    QJsonObject json;
    int randomNumber = QRandomGenerator::global()->bounded(10000,100000);
    QString dateTime = QDateTime::currentDateTime().toString("yyyyMMddhhmmssSSS");

    json["factoryNo"] = factoryNo;
    json["transId"] = QString("%1%2").arg(dateTime).arg(randomNumber);
    json["eventTime"] = eventTime.toString("yyyy-mm-dd hh:mm:ss");
    json["eventUser"] = eventUser;
    json["connectStatus"] = connectStatus;
    return QJsonDocument(json).toJson();
}

QString HeartbeatDetectionRequest::getEndPoint() const
{
    return "/api/getech-mes/IotController/heartbeat";
}
